//
//  KZTabBarItem.m
//  JHStore
//
//  Created by kiefer on 14-10-16.
//  Copyright (c) 2014年 kiefer. All rights reserved.
//

#import "KZTabBarItem.h"

@implementation KZTabBarItem

- (void)dealloc
{
    [titleLabel release]; titleLabel = nil;
    [_font release]; _font = nil;
    [_title release]; _title = nil;
    [_titleColor release]; _titleColor = nil;
    [_titleColorSelected release]; _titleColorSelected = nil;
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        titleLabel = [[UILabel alloc] init];
        titleLabel.backgroundColor = [UIColor clearColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:titleLabel];
        
        _font = [[UIFont systemFontOfSize:15.0f] retain];
        _titleColor = [[UIColor blackColor] retain];
        _titleColorSelected = [NAVBAR_COLOR retain];
    }
    return self;
}

- (void)setTitle:(NSString *)title
{
    if (_title != title) {
        [_title release];
        _title = [title retain];
        
        [self setNeedsLayout];
    }
}

- (void)setSelected:(BOOL)selected
{
    if (_selected != selected) {
        _selected = selected;
        
        [self setNeedsLayout];
    }
}

- (BOOL)isSelected
{
    return _selected;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat boundsW = self.bounds.size.width;
    CGFloat boundsH = self.bounds.size.height;
    
    titleLabel.text = _title;
    titleLabel.font = _font;
    titleLabel.frame = CGRectMake(0, 0, boundsW, boundsH);
    
    if (![self isSelected]) {
        titleLabel.textColor = _titleColor;
    } else {
        titleLabel.textColor = _titleColorSelected;
    }
}

@end
